gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\datasets\pgm2x.m
function [x,width,height]=pgm2x(fname, normalize) % PGM2X leads PGM image from file. % [x,width,height]=pgm2x(fname, normalize) % % PGM2X loads an image from file which must be in the PGM % format. The loaded image is returned as a column vector % of doubles. If normalize is set to 1 then image values % will be normalized to range <0,1>. % % % Input: % fname [string] file nam of the image. % normalize [int] if equal to 1 then output x is in range <0,1>. % % Output: % x [width x height] vector containg read image. % width [1x1] width of the image. % height [1x1] height of the image. % % See also X2PGM % % Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac % (c) Czech Technical University Prague, http://cmp.felk.cvut.cz % Written Vojtech Franc (diploma thesis) % Modifications % 27-sep-2001, V.Franc, argument normallized % 26-feb-2001 V.Franc if nargin < 2, normalize = 0; end fid=fopen(fname,'r'); line1=fgets(fid); line2=fgets(fid); line3=fgets(fid); a = sscanf(line2,'%d'); width=a(1); height=a(2); prec= sscanf(line3, '%d'); if prec==255, precision='uchar'; elseif prec==65535, precision='int16'; end [x, count] = fread(fid,inf,precision); fclose(fid); if count ~= width*height, error('Invalid input format.'); return; end x=x(:); if normalize == 1, x=double(x)/prec; end return;